package top.idcard.agent.biz.rw.read.device;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author wx
 * @version 1.0
 * @date 2021/2/2 9:37 上午
 */
public enum FunctionResultEnum {

    SUCCESS(1, "成功"),
    FAILED(0, "失败"),
    NUll_NOT_ENOUGH(-2, "第一个参数分配的内存空间不足或为空指针"),
    NOT_CONNECTED(-1, "未连接读卡器"),
    INIT_REPEAT_OPTION(2, "重复操作，设备已打开"),
    INIT_UNKNOW_PROTOCOL_TYPE(3, "未识别的协议类型"),
    INIT_DEVICE_FILE_PATH_ERROR(4, "打开设备路径文件失败"),
    INIT_DEVICE_INIT_FAILED(5, "设备初始化失败"),
    INIT_UNKNOW_ERROR(-1, "未知错误"),
    AU_FIND_CARED_FAILED(2, "寻卡失败"),
    AU_CHOOSE_CARD_FAILED(3, "选卡失败"),
    AU_NOT_CONNECTED(4, "未连接读卡器"),
    CLOSE_FAILED(0, "关闭失败"),
    CLOSE_NOT_CONNECTED(4, "未连接读卡器"),
    STATUS_ERROR(0, "状态异常"),
    STATUS_NORMAL(1, "状态正常"),
    STATUS_NOT_CONNECTED(4, "未连接读卡器");

    private Integer code;
    private String msg;

    FunctionResultEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public static FunctionResultEnum valueOf(Integer code){
        Optional<FunctionResultEnum> optional = Arrays.stream(FunctionResultEnum.values()).filter(item->item.getCode() == code).findFirst();
        return optional.orElseGet(null);
    }
}
